package com.drojian;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

import java.util.ArrayList;
import java.util.List;

import jp.wasabeef.glide.transformations.ColorFilterTransformation;

public class GlideTransformationAdapter extends RecyclerView.Adapter<GlideTransformationAdapter.ViewHolder>{
    private Context mContext;
    private List<String> mData = new ArrayList<>();
    public GlideTransformationAdapter(Context context) {
        mContext = context;
        for (int i = 0; i < 21; i++) {
            mData.add(i+"");
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.item_glide_transformation, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.textView.setText("item"+(position+1));
        int i = Integer.parseInt(mData.get(position));
        switch (i){
            case 1:{
                Glide.with(mContext)
                        .load(R.drawable.img)
                        .into(holder.imageView);
                break;
            }
            case 2:{
                Glide.with(mContext)
                        .load(R.drawable.img)
                        .apply(RequestOptions.bitmapTransform(new RoundedCorners(100)))
                        .into(holder.imageView);
                break;
            }
            case 3:{
                Glide.with(mContext)
                        .load(R.drawable.img)
                        .apply(RequestOptions.bitmapTransform(new ColorFilterTransformation(Color.RED)))
                        .into(holder.imageView);
                break;
            }
            case 4:{
                Glide.with(mContext)
                        .load(R.drawable.img)
                        .apply(RequestOptions.fitCenterTransform())
                        .into(holder.imageView);
                break;
            }


        }
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView imageView;
        private TextView textView;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.imageView);
            textView = itemView.findViewById(R.id.textView);

        }
    }
}
